/**
 * desc: integer validator
 * author: Joe
 * date: 7/26/2018
 */

var INTEGER_REGEXP = /^[-+]?\d+$/;
coreModule.directive('integer', function() {
  return {
    require: 'ngModule',
    link: function(scope, elm, attrs, ctrl) {
      ctrl.$validators.integer = function(modelValue, viewValue) {
        if (ctrl.$isEmpty(modelValue)) {
          return true;
        }

        return INTEGER_REGEXP.test(viewValue);
      };
    }
  };
});
